﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NLog;


namespace AWS_FTP.Utilities
{
    //Enumerating LogTypes
    public enum LogType { TRACE, DEBUG, INFO, ERROR, WARN }

    public class AWSLogger
    {        
        public AWSLogger() { }

        public static void Write(String message, Exception exception, LogType type = LogType.ERROR)
        {
            try
            {
                //Initiating Logger
                Logger log = LogManager.GetLogger("f");

                //Logger message commuter
                var error = string.Empty;

                //Feeding a detailed description of the exception raised to the log message.
                if (exception != null)
                {
                    error = string.Join(".", message,
                        string.IsNullOrEmpty(exception.Message) ? string.Empty : exception.Message,
                        (exception.InnerException == null) ? string.Empty : (string.IsNullOrEmpty(exception.InnerException.Message) ? string.Empty : exception.InnerException.Message),
                        string.IsNullOrEmpty(exception.StackTrace) ? string.Empty : exception.StackTrace,
                        string.IsNullOrEmpty(exception.HelpLink) ? string.Empty : exception.HelpLink);
                }
                else
                {
                    //If the no exception is thrown. i.e.,could be a trace or info that has to be logged.
                    error = message;
                }

                //Writing logs for the given log type
                switch (type)
                {
                    case LogType.DEBUG:
                        log.Debug(error);
                        break;
                    case LogType.ERROR:
                        log.Error(error);
                        break;
                    case LogType.INFO:
                        log.Info(error);
                        break;
                    case LogType.TRACE:
                        log.Trace(error);
                        break;
                    case LogType.WARN:
                        log.Warn(error);
                        break;
                    default:
                        log.Log(LogLevel.Off, "Failed to write a log...!");
                        break;
                }
            }
            catch { }
        }
    }
}